import java.util.*;

public class Anagram {
    public static void main(String[] args) {
        
        Scanner keybordInput = new Scanner(System.in);
        System.out.print("Enter first word:");
        String inputWord = keybordInput.nextLine();
        System.out.print("Enter anagram of first word:");
        String anagram = keybordInput.nextLine();
        
        inputWord = inputWord.toLowerCase();
        anagram = anagram.toLowerCase();
        while(inputWord.indexOf(' ') != -1) {
            inputWord = inputWord.substring(0,inputWord.indexOf(' ')) + inputWord.substring(inputWord.indexOf(' ')+1);
        }
        
        for(int charAnagramIndex = 0; charAnagramIndex < anagram.length(); charAnagramIndex++) {
            char temporaryChar = anagram.charAt(charAnagramIndex);
            if(temporaryChar == ' ') {
                continue;
            }
            int charInputWordIndex = inputWord.indexOf(temporaryChar);
            if (charInputWordIndex == -1) {
                System.out.println("These words are not anagram");
                break;
            }
            else {
                inputWord = inputWord.substring(0,charInputWordIndex) + inputWord.substring(charInputWordIndex+1);
            }
        }
        if (inputWord.length() == 0) {
            System.out.println("These words are anagram");
        }
        else {
            System.out.println("These words are not anagram");
        }
    }
}